/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package yoga.gui;

import java.awt.Polygon;
import java.io.File;

/**
 *
 * @author Yogev Montekyo
 */
public class JFramePolygonPairViewer extends javax.swing.JFrame
{
    /**
     * Creates new form JFramePolygonPairViewer
     */
    public JFramePolygonPairViewer()
    {
        initComponents();
    }

    public void setLeftPolygonPanel(Polygon polygon, String text)
    {
        this.jPanelPolygonLeft.setPolygon(polygon, text);
    }

    public void setRightPolygonPanel(Polygon polygon, String text)
    {
        this.jPanelPolygonRight.setPolygon(polygon, text);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents()
    {

        jPanelPolygonVisualization1 = new yoga.gui.JPanelPolygonVisualization();
        jPanelPolygonLeft = new yoga.gui.JPanelPolygonVisualization();
        jPanelPolygonRight = new yoga.gui.JPanelPolygonVisualization();
        jSliderRate = new javax.swing.JSlider();
        jLabelAboveSlider = new javax.swing.JLabel();
        jLabelAboveSlider1 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextAreaRight = new javax.swing.JTextArea();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTextAreaLeft = new javax.swing.JTextArea();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        getContentPane().setLayout(new java.awt.GridLayout(1, 2));

        jPanelPolygonLeft.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jPanelPolygonLeft.setMaximumSize(new java.awt.Dimension(400, 400));
        jPanelPolygonLeft.setPreferredSize(new java.awt.Dimension(500, 500));

        javax.swing.GroupLayout jPanelPolygonLeftLayout = new javax.swing.GroupLayout(jPanelPolygonLeft);
        jPanelPolygonLeft.setLayout(jPanelPolygonLeftLayout);
        jPanelPolygonLeftLayout.setHorizontalGroup(
            jPanelPolygonLeftLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 446, Short.MAX_VALUE)
        );
        jPanelPolygonLeftLayout.setVerticalGroup(
            jPanelPolygonLeftLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );

        jPanelPolygonRight.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jPanelPolygonRight.setMaximumSize(new java.awt.Dimension(500, 500));
        jPanelPolygonRight.setPreferredSize(new java.awt.Dimension(500, 500));

        javax.swing.GroupLayout jPanelPolygonRightLayout = new javax.swing.GroupLayout(jPanelPolygonRight);
        jPanelPolygonRight.setLayout(jPanelPolygonRightLayout);
        jPanelPolygonRightLayout.setHorizontalGroup(
            jPanelPolygonRightLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 446, Short.MAX_VALUE)
        );
        jPanelPolygonRightLayout.setVerticalGroup(
            jPanelPolygonRightLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 446, Short.MAX_VALUE)
        );

        jSliderRate.setMinimum(1);
        jSliderRate.setMinorTickSpacing(10);
        jSliderRate.setPaintTicks(true);
        jSliderRate.setSnapToTicks(true);
        jSliderRate.setValue(30);
        jSliderRate.setCursor(new java.awt.Cursor(java.awt.Cursor.MOVE_CURSOR));

        jLabelAboveSlider.setText("Slow");

        jLabelAboveSlider1.setText("Fast");

        jTextAreaRight.setColumns(20);
        jTextAreaRight.setRows(5);
        jScrollPane1.setViewportView(jTextAreaRight);

        jTextAreaLeft.setColumns(20);
        jTextAreaLeft.setRows(5);
        jScrollPane2.setViewportView(jTextAreaLeft);

        javax.swing.GroupLayout jPanelPolygonVisualization1Layout = new javax.swing.GroupLayout(jPanelPolygonVisualization1);
        jPanelPolygonVisualization1.setLayout(jPanelPolygonVisualization1Layout);
        jPanelPolygonVisualization1Layout.setHorizontalGroup(
            jPanelPolygonVisualization1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelPolygonVisualization1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelPolygonVisualization1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelPolygonVisualization1Layout.createSequentialGroup()
                        .addGroup(jPanelPolygonVisualization1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanelPolygonVisualization1Layout.createSequentialGroup()
                                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 450, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 450, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanelPolygonVisualization1Layout.createSequentialGroup()
                                .addComponent(jPanelPolygonLeft, javax.swing.GroupLayout.PREFERRED_SIZE, 450, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jPanelPolygonRight, javax.swing.GroupLayout.PREFERRED_SIZE, 450, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(0, 15, Short.MAX_VALUE))
                    .addGroup(jPanelPolygonVisualization1Layout.createSequentialGroup()
                        .addComponent(jLabelAboveSlider)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jSliderRate, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabelAboveSlider1)))
                .addContainerGap())
        );
        jPanelPolygonVisualization1Layout.setVerticalGroup(
            jPanelPolygonVisualization1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelPolygonVisualization1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelPolygonVisualization1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jPanelPolygonRight, javax.swing.GroupLayout.DEFAULT_SIZE, 450, Short.MAX_VALUE)
                    .addComponent(jPanelPolygonLeft, javax.swing.GroupLayout.DEFAULT_SIZE, 450, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelPolygonVisualization1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabelAboveSlider)
                    .addComponent(jSliderRate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelAboveSlider1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelPolygonVisualization1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 134, Short.MAX_VALUE)
                    .addComponent(jScrollPane2))
                .addContainerGap())
        );

        getContentPane().add(jPanelPolygonVisualization1);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
     * @param args the command line arguments
     */
    public static void main(String args[])
    {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try
        {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels())
            {
                if ("Nimbus".equals(info.getName()))
                {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        }
        catch (ClassNotFoundException ex)
        {
            java.util.logging.Logger.getLogger(JFramePolygonPairViewer.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        catch (InstantiationException ex)
        {
            java.util.logging.Logger.getLogger(JFramePolygonPairViewer.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        catch (IllegalAccessException ex)
        {
            java.util.logging.Logger.getLogger(JFramePolygonPairViewer.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        catch (javax.swing.UnsupportedLookAndFeelException ex)
        {
            java.util.logging.Logger.getLogger(JFramePolygonPairViewer.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable()
        {
            public void run()
            {
                new JFramePolygonPairViewer().setVisible(true);
            }
        });
    }

    public synchronized void setLeftText(String text)
    {
        jTextAreaLeft.setText(text);

    }

    public synchronized void setRightText(String text)
    {
        jTextAreaRight.setText(text);

    }
    
    public synchronized void saveLeftPanelAsJpeg(File file)
    {        
        GraphicsUtils.saveGraphicsToJpeg(jPanelPolygonLeft,file);        
    }
    
    public synchronized void saveRightPanelAsJpeg(File file)
    {        
        GraphicsUtils.saveGraphicsToJpeg(jPanelPolygonRight,file);        
    }

    public synchronized int getSliderValue()
    {
        return jSliderRate.getValue();
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabelAboveSlider;
    private javax.swing.JLabel jLabelAboveSlider1;
    private yoga.gui.JPanelPolygonVisualization jPanelPolygonLeft;
    private yoga.gui.JPanelPolygonVisualization jPanelPolygonRight;
    private yoga.gui.JPanelPolygonVisualization jPanelPolygonVisualization1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JSlider jSliderRate;
    private javax.swing.JTextArea jTextAreaLeft;
    private javax.swing.JTextArea jTextAreaRight;
    // End of variables declaration//GEN-END:variables
}
